unit subcontrTotal;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Provider, SqlExpr, DB, DBClient, DBLocal, DBLocalS, StdCtrls,
  DBCtrls, Grids, DBGrids, RXDBCtrl, Mask, ToolEdit, DateUtils, Buttons,
  ppCtrls, ppBands, ppVar, ppPrnabl, ppClass, ppCache, ppProd, ppReport,
  ppDB, ppComm, ppRelatv, ppDBPipe, ppTypes;

type
  TfrmSubcontrTotal = class(TForm)
    lblFechaIni: TLabel;
    edtFechaIni: TDateEdit;
    lblFechaFin: TLabel;
    edtFechaFin: TDateEdit;
    grdSubc: TRxDBGrid;
    Label2: TLabel;
    Label1: TLabel;
    Label3: TLabel;
    enMano: TDBText;
    cargaSocial: TDBText;
    total: TDBText;
    btnCargar: TButton;
    cds: TSQLClientDataSet;
    cdsCARGA: TFloatField;
    cdsMANO: TFloatField;
    cdssubTCarga: TAggregateField;
    cdssubtMano: TAggregateField;
    cdstotal: TAggregateField;
    s: TDataSource;
    cdsRAZON: TStringField;
    cdsSUBTOTAL: TFloatField;
    ppSubTotal: TppDBPipeline;
    ppComprasMaterialppField1: TppField;
    ppComprasMaterialppField2: TppField;
    ppComprasMaterialppField3: TppField;
    ppComprasMaterialppField4: TppField;
    rpSubObra: TppReport;
    ppHeaderBand1: TppHeaderBand;
    ppDBImage1: TppDBImage;
    ppLabel8: TppLabel;
    ppEmail: TppLabel;
    ppTe: TppLabel;
    ppDBText3: TppDBText;
    ppDBText6: TppDBText;
    ppLine4: TppLine;
    ppLabel5: TppLabel;
    ppLabel6: TppLabel;
    ppLine1: TppLine;
    ppLabel2: TppLabel;
    ppLabel3: TppLabel;
    ppSystemVariable1: TppSystemVariable;
    ppDetailBand1: TppDetailBand;
    ppLine3: TppLine;
    datMaterial: TppDBText;
    datUnitario: TppDBText;
    ppDBText1: TppDBText;
    ppDBText2: TppDBText;
    ppFooterBand1: TppFooterBand;
    ppLabel1: TppLabel;
    ppDBCalc1: TppDBCalc;
    ppLabel4: TppLabel;
    ppDBCalc2: TppDBCalc;
    ppLabel7: TppLabel;
    ppDBCalc3: TppDBCalc;
    ppEmpresa: TppDBPipeline;
    ppEmpresappField1: TppField;
    ppEmpresappField2: TppField;
    ppEmpresappField3: TppField;
    ppEmpresappField4: TppField;
    ppEmpresappField5: TppField;
    ppEmpresappField6: TppField;
    ppEmpresappField7: TppField;
    ppEmpresappField8: TppField;
    ppEmpresappField9: TppField;
    ppEmpresappField10: TppField;
    ppEmpresappField11: TppField;
    ppEmpresappField12: TppField;
    ppEmpresappField13: TppField;
    ppEmpresappField14: TppField;
    ppEmpresappField15: TppField;
    sEmpresa: TDataSource;
    btnVistaPrevia: TBitBtn;
    btnExcel: TSpeedButton;
    procedure btnCargarClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure grdSubcTitleClick(Column: TColumn);
    procedure FormCreate(Sender: TObject);
    procedure btnVistaPreviaClick(Sender: TObject);
    procedure btnExcelClick(Sender: TObject);
  private
    { Private declarations }
  public
    constructor CreateNuevo(AOwner: TComponent);
  end;

var
  frmSubcontrTotal: TfrmSubcontrTotal;

implementation

uses Recursos;


{$R *.dfm}

constructor TfrmSubcontrTotal.CreateNuevo(AOwner: TComponent);
begin
  inherited Create(Aowner);
  self.edtFechaIni.Date := IncYear(now, -1);
  self.edtFechaFin.Date := now;
  self.ShowModal;
end;  

procedure TfrmSubcontrTotal.btnCargarClick(Sender: TObject);
begin
  self.cds.Close;
  self.cds.Params[0].AsString := FormatDateTime('mm/dd/yy', StrToDate(self.edtFechaFin.EditText));
  self.cds.Params[1].AsString := FormatDateTime('mm/dd/yy', incDay(StrToDate(self.edtFechaIni.EditText)));
  self.cds.Open;
end;

procedure TfrmSubcontrTotal.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  self.cds.Close;
end;

procedure TfrmSubcontrTotal.grdSubcTitleClick(Column: TColumn);
begin
  self.cds.IndexFieldNames := Column.FieldName;
end;

procedure TfrmSubcontrTotal.FormCreate(Sender: TObject);
begin
  acomodo(self);
end;

procedure TfrmSubcontrTotal.btnVistaPreviaClick(Sender: TObject);
begin
  if (self.cds.State in [dsInactive]) then
    self.btnCargarClick(Sender);
  self.rpSubObra.DeviceType := dtScreen;
  self.rpSubObra.Print;
end;

procedure TfrmSubcontrTotal.btnExcelClick(Sender: TObject);
begin
  abrirEnExcel(self, self.cds, nil, nil, 'PAGOS A SUBCONTRATISTAS', 'INTERVALO DEFINIDO: del '
  +DateTimeToStr(self.edtFechaIni.Date)+' al '+DateTimeToStr(self.edtFechaFin.Date));
end;

end.
 